<template>
	<view class="wrap">
		<view class="shopWrap" v-for="item in showList" :key="item.goods_id">
			<view class="goodsPic">
				<image :src="item.goods_pic[0].pics_url" mode="widthFix"></image>
			</view>
			<view class="goodsInfo">
				<view class="goodsName">{{item.goods_name}}</view>
				<view class="control">
					<view class="goodsPrice">￥{{item.goods_price}}</view>
					<view class="bottomContrl">
						<view class="cutBtn" @click="cutNum(item.goods_id)">-</view>
						<input type="text" name="" :value="item.goods_num" />
						<view class="addbtn" @click="addNum(item.goods_id)">+</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"uni-shop-item",
		props:{
			showList:Array,
			shopList:Array,
			loginInfo:"",
			getTotal:{
				type:Function,
				default:null
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			addNum(id){
				this.shopList.forEach(v=>{
					if(v.goods_id==id){
						v.goods_num +=1
					}
				})
				uni.setStorageSync("shopList",this.shopList)
				this.getTotal()
				//this.$emit("demo")
			},
			cutNum(id){
				this.showList.forEach((v,i)=>{
					if(v.goods_id==id){
						if(v.goods_num>1){
						//	v.goods_num-=1
							this.shopList.forEach((v,i)=>{
								if(v.goods_id==id){
									this.shopList[i].goods_num -=1
								}
							})
						}else{
							uni.showToast({
								title:"删除成功",
								icon:"error"
							})
							this.shopList.forEach((v,i)=>{
								if(v.goods_id==id){
									if(v.loginInfo ==this.loginInfo){}
									this.shopList.splice(i,1)
								}
							})
							this.showList.splice(i,1)
						}
					}
				})
				uni.setStorageSync("shopList",this.shopList)
				this.getTotal()
			}
		}
	}
</script>

<style lang="less">
.wrap{
	padding: 30rpx 30rpx 80rpx;
	.shopWrap{
		display: flex;
		border-bottom:  1rpx solid #efefef;
		.goodsPic{
			flex: 3;
			image{
				width: 100%;
				padding: 5rpx 10rpx;
			}
		}
		.goodsInfo{
			flex: 5;
			display: flex;
			flex-direction: column;
			justify-content: center;
			.goodsName{
				font-size: 36rpx;
				font-weight: bold;
			}
			.control{
				display: flex;
				.goodsPrice{
					flex: 1;
				}
				.bottomContrl{
					flex: 2;
					display: flex;
					.cutBtn,.addbtn{
						width: 80rpx;
						height: 50rpx;
						background-color: #efefef;
						border: 1rpx solid gray;
						font-size: 36rpx;
						font-weight: bold;
						display: flex;
						justify-content: center;
						align-items: center;
					}
					input{
						width: 80rpx;
						height: 50rpx;
						background-color: #eee;
						text-align: center;
					}
				}
			}
		}
	}
}
</style>
